package com.ibm.cps.message;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Set;

public abstract class ProcessorMetaMessage extends AbstractMessage {

	protected String processorid;
	protected Set<String> parentprocessors;

	public ProcessorMetaMessage() {
		// Spark Workaround
		// processorid = "";
	}

	public Set<String> getParentProcessors() {
		return parentprocessors;
	}

	public String getProcessorId() {
		return processorid;
	}

	/**
	 * update the map from parent to successors when this processor is added
	 * @param parent2Successors
	 */
	public abstract void updateProcessorMap(
			HashMap<String, Set<String>> parent2Successors);

	@Deprecated
	public List<List<Object>> deleteProcessor(
			HashMap<String, Set<String>> parent2Successors) {
		// List<String> affectedProcessors = new ArrayList<String>();
		// List<String> affectedProcessors1 = deletion.deleteAffectedProcessors(
		// processorid, parent2Successors);
		// if (affectedProcessors1 != null) {
		// affectedProcessors.addAll(affectedProcessors1);
		// }
		// List<String> affectedProcessors2 = deletion
		// .deleteAffectedProcessors(processorid
		// + MessageFields.PROCESSOR_SUFFIX, parent2Successors);
		// if (affectedProcessors2 != null) {
		// affectedProcessors.addAll(affectedProcessors2);
		// }
		// if (affectedProcessors.size() < 1) {
		// return null;
		// }
		// return getUpdateMessages(affectedProcessors);
		return null;
	}

	/**
	 * send affected processors to next bolt
	 * @param affectedProcessors
	 * @return
	 */
	public List<List<Object>> getUpdateMessages(List<String> affectedProcessors) {
		List<List<Object>> retMsg = new ArrayList<List<Object>>();
		for (String parent : affectedProcessors) {
			System.out.println("Affect processor " + parent);
			List<Object> newObjects = new ArrayList<>();
			newObjects.add(type);
			newObjects.add(processorid);
			newObjects.add(parent);
			retMsg.add(newObjects);
		}
		return retMsg;
	}

}
